package com.HMS.controller;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.HMS.entity.VerifyImage;
import com.HMS.mark.Verify;

@Controller
@RequestMapping("/HelpTool")
public class HelpTool {
	@Resource
	private Verify verify;
	private VerifyImage verifyImage;
	//输出验证码
	@RequestMapping(value="/verify")
	public void verify(HttpServletRequest request,HttpServletResponse response){
		response.setHeader("Pragma", "No-cache");
		response.setHeader("Cache-Control", "No-cache");
		response.setDateHeader("Expires", -10); 
		verifyImage=verify.getImage(120, 25, BufferedImage.TYPE_INT_RGB);
		request.getSession().setAttribute("verity", verifyImage.getVerifyCode());		
		ServletOutputStream os;
		try {
			os = response.getOutputStream();		
		response.setContentType("image/jpeg");
			ImageIO.write(verifyImage.getImg(), "jpg", os);
			os.close();			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
	}

}
